package wviz.gui.color;

import prefuse.Visualization;
import prefuse.action.assignment.ColorAction;
import prefuse.util.ColorLib;
import prefuse.visual.VisualItem;
import prefuse.visual.VisualTable;

/**
 * @author : Mohammad Asgari
 * @date: Sep 10, 2008
 */
public class NodeColorAction extends ColorAction {
	public NodeColorAction(String group) {
		super(group, VisualItem.FILLCOLOR, ColorLib.rgb(250, 200, 230));// (61,
																		// 130,
																		// 246));
		add("_hover and ingroup('" + Visualization.SELECTED_ITEMS + "')",
				ColorLib.rgb(0, 190, 204));
		// search results
		add("_hover and ingroup('_search_')",
				ColorLib.brighter(ColorLib.rgb(152, 255, 92)));
		add("_hover", ColorLib.brighter(ColorLib.rgb(61, 130, 246)));
		// selected subtrees
		add("ingroup('" + Visualization.SELECTED_ITEMS + "')",
				ColorLib.rgb(0, 190, 204));
		// search results
		add("ingroup('_search_')", ColorLib.rgb(152, 255, 92));
		// the root
		add("ingroup('_focus_')", ColorLib.rgb(198, 229, 229));
	}

	// TODO:added by Hadi
	@Override
	public int getColor(VisualItem item) {
		// return super.getColor(item);

		int color = super.getColor(item);

		int row = item.getRow();

		VisualTable visTable = (VisualTable) item.getTable();

		String word = null;
		int links = 1;

		try {
			word = visTable.getString(row, "word");
			links = visTable.getInt(row, "links");
		} catch (Exception e) {
			return color;
		}
		if (word != null) {
			if (color != 0) {

				links = visTable.getInt(row, "links");

				int MAX_LINKS = 6;

				if (links > 4)
					return ColorLib.rgb(204, 54, 255);
				else if (links > 2)
					return ColorLib.rgb(51, 255, 204);
				else
					return ColorLib.rgb(51, 204, 255);
			}
		}
		return color;

	}

} // end of inner class NodeColorAction
